<?php
/**
 * Created by PhpStorm.
 * User: antely
 * Date: 2018/4/26
 * Time: 11:58
 * 验证码验证
 */
namespace app\api\validate;
use think\{Validate,Db};
class Code extends Validate{
    protected $SmsCheckCode = 'SmsCheckCode';//验证码表
    // 验证规则
    protected $rule = [
        ['mobile', 'require|regex:/^1[34578]\d{9}$/', '-10668|-10669'],
        ['code', 'require', '-10670'],
        ['uid','require','-10301'],
        ['openId','require','-14065'],
        ['wx_code','require','-23033'],
        ['name','require','-10014'],
        ['sex','require','-37003'],
        ['appid','require','-50038'],
        ['password','require','-50042']
    ];
    protected $scene = [
        'send_code_mobile' => ['uid', 'mobile'],
        'check_code_mobile' => ['mobile', 'code','openId','uid'],
        'check_register_mobile' => ['mobile', 'code','openId','name','sex'],
        'check_register_mobile_nocode' => ['mobile','openId','name','sex'],
        'send_code_single_mobile' => ['mobile'],
        'code' => ['wx_code','appid'],
        'login'=>['mobile','password','openId'],
        'updata_mobile'=>['mobile','code','uid']
    ];

    //检测是否存在该条数据
    protected function is_exist($value, $rule, $data){
        $check = explode("/", $rule);
        $db_name = $check[0];
        $check_field = $check[1];
        $res = Db::connect(config('database.db_config1'))->name($db_name)->where($check_field . '=' . $value)->find();
        return $res ? true : -400;
    }
}